home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / Komunik / Webscr / HTMLtool / _SETUP.1 / Faded Text.scp < prev    next >
Text File  |  1999-10-03  |  4KB  |  133 lines

  1. <HTMLtool>Example of color-fade</HTMLtool>
  2. <body onLoad="ticker()">
  3.  
  4. <script language="JavaScript">
  5. <!-- Hide the script from old browsers --
  6. function MakeArray(n){   
  7.     this.length=n;   
  8.     for(var i=1; i<=n; i++) this[i]=i-1;   
  9.         return this
  10.     }
  11.     hex=new MakeArray(16);
  12.     hex[11]="A"; 
  13.     hex[12]="B"; 
  14.     hex[13]="C"; 
  15.     hex[14]="D"; 
  16.     hex[15]="E"; 
  17.     hex[16]="F";
  18.  
  19. function ToHex(x){              
  20.     // Changes a int to hex (in the range 0 to 255)   
  21.     var high=x/16;   
  22.     var s=high+"";               
  23.     //1   
  24.     s=s.substring(0,2);          
  25.     //2 the combination of these are the same as the trunc function   
  26.     high=parseInt(s,10);         
  27.     //3   
  28.     var left=hex[high+1];        
  29.     // left part of the hex-value   
  30.     var low=x-high*16;           
  31.     // calculate the rest of the values   
  32.     s=low+"";                    
  33.     //1   
  34.     s=s.substring(0,2);          
  35.     //2 the combination of these are the same as the trunc function   
  36.     low=parseInt(s,10);          
  37.     //3   
  38.     var right=hex[low+1];        
  39.     // right part of the hex-value   
  40.     var string=left+""+right;    
  41.     // add the high and low together   
  42.     return string;
  43. }
  44.  
  45. function fadein(text){   
  46.     text=text.substring(3,text.length-4);        
  47.     // gets rid of the HTML-comment-tags   
  48.     color_d1=255;                                
  49.     color_d1b=255;
  50.     color_d1c=255;
  51.     // any value in 'begin' 0 to 255   
  52.     mul=color_d1/text.length;   
  53.     for(i=0;i<text.length;i++){      
  54.         color_d1=mul*i; 
  55.         color_d1b=255-mul*i;
  56.         color_d1c=255*Math.sin(i/(text.length/3));
  57.  
  58.         // some other things you can try>> "=255-mul*i" to fade out, "=mul*i" to fade in, or try "255*Math.sin(i/(text.length/3))"      
  59.         color_h1=ToHex(color_d1);      
  60.         color_d2=mul*i;      
  61.         color_h2=ToHex(color_d2);      
  62.         //1b
  63.         color_h1b=ToHex(color_d1b);      
  64.         color_d2b=mul*i;      
  65.         color_h2b=ToHex(color_d2b);      
  66.         //1c
  67.         color_h1c=ToHex(color_d1c);      
  68.         color_d2c=mul*i;      
  69.         color_h2c=ToHex(color_d2c);      
  70.  
  71.         document.write("<FONT COLOR='#FF"+color_h1+color_h2+"'>"+text.substring(i,i+1)+'</FONT>');   
  72.  
  73.     }
  74.     document.write('<p>');
  75.     for(i=0;i<text.length;i++){      
  76.         color_d1=mul*i; 
  77.         color_d1b=255-mul*i;
  78.         color_d1c=255*Math.sin(i/(text.length/3));
  79.  
  80.         // some other things you can try>> "=255-mul*i" to fade out, "=mul*i" to fade in, or try "255*Math.sin(i/(text.length/3))"      
  81.         color_h1=ToHex(color_d1);      
  82.         color_d2=mul*i;      
  83.         color_h2=ToHex(color_d2);      
  84.         //1b
  85.         color_h1b=ToHex(color_d1b);      
  86.         color_d2b=mul*i;      
  87.         color_h2b=ToHex(color_d2b);      
  88.         //1c
  89.         color_h1c=ToHex(color_d1c);      
  90.         color_d2c=mul*i;      
  91.         color_h2c=ToHex(color_d2c);      
  92.  
  93.         document.write("<FONT COLOR='#FF"+color_h1c+color_h2c+"'>"+text.substring(i,i+1)+'</FONT>');   
  94.  
  95.     }
  96.     document.write('<p>');
  97.     for(i=0;i<text.length;i++){      
  98.         color_d1=mul*i; 
  99.         color_d1b=255-mul*i;
  100.         color_d1c=255*Math.sin(i/(text.length/3));
  101.  
  102.         // some other things you can try>> "=255-mul*i" to fade out, "=mul*i" to fade in, or try "255*Math.sin(i/(text.length/3))"      
  103.         color_h1=ToHex(color_d1);      
  104.         color_d2=mul*i;      
  105.         color_h2=ToHex(color_d2);      
  106.         //1b
  107.         color_h1b=ToHex(color_d1b);      
  108.         color_d2b=mul*i;      
  109.         color_h2b=ToHex(color_d2b);      
  110.         //1c
  111.         color_h1c=ToHex(color_d1c);      
  112.         color_d2c=mul*i;      
  113.         color_h2c=ToHex(color_d2c);      
  114.  
  115.         document.write("<FONT COLOR='#FF"+color_h1b+color_h2b+"'>"+text.substring(i,i+1)+'</FONT>');   
  116.  
  117.     }
  118.  
  119. }
  120. // --End Hiding Here -->
  121. </script>
  122. <center><font size=7>Faded Text</font>
  123. <hr width=80%>
  124.  
  125. <SCRIPT LANGUAGE="JavaScript">
  126. <!--   
  127. {
  128.     fadein("-->THIS IS WHERE YOUR TEXT GOES<!__");
  129. }
  130. //-->
  131. </SCRIPT>
  132. </center>
  133.